//
//  XMLRealsePersonInformation.m
//  ppkc2016
//
//  Created by 拼凑的断音 on 16/3/31.
//  Copyright © 2016年 拼凑的断音. All rights reserved.
//

#import "XMLRealsePersonInformation.h"
#import "XXTool.h"

@implementation XMLRealsePersonInformation

+(instancetype)modelWithDictionary:(NSDictionary *)dict
{
    XMLRealsePersonInformation *model = [super modelWithDictionary:dict];
    NSArray *exInfoArray = [dict objectForKey:@"zslist"];
    NSArray *photoArray = [dict objectForKey:@"list"];
    if ([model.zstotal intValue]==0)
    {
        model.zslist = [NSArray array];
    }
    else
    {
        NSMutableArray *zslist = [[NSMutableArray alloc] init];
        for (int i=0; i<exInfoArray.count; i++)
        {
            XMLNameAndValueModel *temp = [XMLNameAndValueModel modelWithDictionary:exInfoArray[i]];
            [zslist addObject:temp];
        }
        model.zslist = zslist;
    }
    if ([model.total intValue]==0)
    {
        model.list = [NSArray array];
    }
    else
    {
        model.list = photoArray;
    }
    return model;
}

+(void)requestRleaseInformationDetailWithGood_Id:(NSString *)goodsID completion:(void (^)(BOOL, XMLRealsePersonInformation *))completion
{
    [DKHTTPRequest sendDataWithShortUrl:@"commerce_trade_goodslistdetail"
                                  Param:[XXTool formatStringWithLanguage:[NSString stringWithFormat:@"userid=%@&passwd=%@&goods_id=%@",[UserInfo shareUserInfo].userID,[UserInfo shareUserInfo].userPassword,goodsID]]
                              ImageArray:nil
                                 TimeOut:10
                              Completion:^BOOL(NSMutableDictionary *serverDic, DKHTTPResponseType bufferType) {
                                  if ([[serverDic objectForKey:@"code"] intValue]==200)
                                  {
                                      if (completion)
                                      {
                                          completion(YES,[XMLRealsePersonInformation modelWithDictionary:serverDic]);
                                      }
                                  }
                                  else
                                  {
                                      if (completion)
                                      {
                                          completion(NO,nil);
                                      }
                                  
                                  }
                                  return YES;
                              } IsBuffering:YES IsNeedReplaceWrap:YES IsUseUpLoadHead:NO];
}

+(void)requestExhibitorCollectVisitorListWithListCount:(NSInteger)count completion:(void (^)(BOOL, NSMutableArray<XMLRealsePersonInformation *> *))block
{
    [DKHTTPRequest sendDataWithShortUrl:@"favorites_exhibitor"
                                  Param:[XXTool formatStringWithLanguage:[NSString stringWithFormat:@"userid=%@&passwd=%@&nstart=%ld&ntotal=10",[UserInfo shareUserInfo].userID,[UserInfo shareUserInfo].userPassword,count]]
                             ImageArray:nil
                                TimeOut:10
                             Completion:^BOOL(NSMutableDictionary *serverDic, DKHTTPResponseType bufferType) {
                                 if ([[serverDic objectForKey:@"code"] intValue]==200)
                                 {
                                     NSMutableArray *list = [NSMutableArray array];
                                     if ([[serverDic objectForKey:@"total"] intValue]!=0)
                                     {
                                         NSArray *tempArray = [serverDic objectForKey:@"exlist"];
                                         for (NSDictionary* temp in tempArray) {
                                             [list addObject:[XMLRealsePersonInformation modelWithDictionary:temp]];
                                         }
                                     }
                                     block(YES,list);
                                 }
                                 else
                                 {
                                     block(NO,nil);
                             
                                 }
                                 return YES;
                             } IsBuffering:YES
                      IsNeedReplaceWrap:YES
                        IsUseUpLoadHead:NO];
}

@end
